
<template>
  <!------------------------------------ 商品简介 ------------------------------------
    @desc 包含标题栏，商品轮播图和视频
    @author kyle
    @date 2021-03-05
    @props
      list         ———— 图片列表
      videoUrl     ———— 视频地址
      scrollTop    ———— 滚动高度
  -->
  <div class="product-intro">
    <h1 class="color-primary fs-32 flex" v-if="ProductInfo.ActivityType==0 || ProductInfo.ActivityType==6">
      <span>￥</span>
      <span class="fs-52">{{ GradePrice_1 }}.</span>
      <span>{{ GradePrice_2 }}</span>
      <span v-show="data.isShowShareEarn==1&&ShareRewardInfo.ShareMoney>0" class="bg-second color-white fs-24 share">分享金￥{{ ShareRewardInfo.ShareMoney }}</span>
      <!--<svg-icon icon-class="like" class="like color-shadow " :class="isFavorite===1?'color-primary':''" @goPage="changeFavState" />-->
    </h1>
    <h1 class="color-primary fs-32 flex" v-if="ProductInfo.ActivityType==1">
      <span>拼团价￥{{ProductInfo.GroupPrice}}</span>
      <span v-show="data.isShowShareEarn==1&&ShareRewardInfo.ShareMoney>0" class="bg-second color-white fs-24 share">分享金￥{{ ShareRewardInfo.ShareMoney }}</span>
      <!--<svg-icon icon-class="like" class="like color-shadow " :class="isFavorite===1?'color-primary':''" @goPage="changeFavState" />-->
    </h1>
    <p v-show="ProductInfo.MarkePrice && ProductInfo.ActivityType==0" class="color-gray-light fs-22 mt-20">原价<span class="oldprice">￥{{ ProductInfo.MarkePrice }}</span></p>
    <p v-show="ProductInfo.MarkePrice && ProductInfo.ActivityType==1" class="color-gray-light fs-22 mt-20">{{ProductInfo.GroupCount}}人团</p>
    <div class="pos-r">
      <h2 class="text-show-line-2 fs-32 mt-20">
        {{ ProductInfo.ProductName }}
      </h2>
      <span class="share-btn" @click="share">
        <svg-icon icon-class="share" class="color-gray-light mr-10" />
        分享
      </span>
    </div>
    <p class="color-gray-light mt-20">{{ ProductInfo.ShortDescription }}</p>
    <div v-show="data.isShowShareEarn==1&&ShareRewardInfo.ShareMoney&&ShareRewardInfo.ShareMoney>0" class="mt-20 upgrade" @click="goUpgrade">
      <img :src="shareImg" alt="" srcset="">
      <p class="color-white fs-28">升级{{ ShareRewardInfo.LastGradeName }}得分享金约￥{{ ShareRewardInfo.LastShareMoney }}</p>
    </div>
    <!-- <van-dialog v-model="shareData.show" :show-confirm-button="shareData.showConfirmButton" close-on-click-overlay> -->
    <div v-show="shareData.show" class="dialog-box">
      <div class="dialog-shadow" @click="shareData.show=false" />
      <div class="dialog-content"> <productShare :detail-data="data" :storeId="storeId" :change-img="shareData.show" /></div>
    </div>

    <!-- </van-dialog> -->
  </div>
</template>

<script>
import shareImg from 'assets/images/share-img.png'
import productShare from 'components/productDetail/share'
import { AddProductToFavorite } from 'api/product'
export default {
  name: 'ProductIntro',
  components: {
    productShare
  },
  props: {
    data: { // 数据
      type: Object,
      required: true,
      default: function() {
        return {}
      }
    },
    storeId: {
      type: String,
      required: false,
      default: ''
    },
  },
  data() {
    return {
      shareImg,
      isAble: true,
      isFavorite: '',
      shareData: {
        show: false,
        showConfirmButton: false
      }
    }
  },
  computed: {
    GradePrice_1() {
      let _price = 0
      if (this.data.ProductInfo && this.data.ProductInfo.V_GradePrice) {
				if (this.data.ProductInfo.scale) {
					_price = (this.data.ProductInfo.V_GradePrice * this.data.ProductInfo.scale).toFixed(2).split('.')[0]
				} else {
					_price = this.data.ProductInfo.V_GradePrice.toFixed(2).split('.')[0]
				}
        
      }
      return _price
    },
    GradePrice_2() {
      let _price = 0
      if (this.data.ProductInfo && this.data.ProductInfo.V_GradePrice) {
        _price = this.data.ProductInfo.V_GradePrice.toFixed(2).split('.')[1]
      }
      return _price
    },
    ProductInfo() {
      const ProductInfo = this.data.ProductInfo || {}
      return ProductInfo
    },
    ShareRewardInfo() {
      const ShareRewardInfo = this.data.ShareRewardInfo || {}
      return ShareRewardInfo
    }
  },
  watch: {
    data(newVal, oldVal) {
      this.isFavorite = newVal.newVal
    }
  },
  created() {
    this.isFavorite = this.data.IsFavorite
		console.log(this.isFavorite,this.data,"收藏")
  },

  methods: {
    // 收藏/取消收藏
    changeFavState() {
      if (this.isAble) {
        const _obj = {}
        _obj.productId = this.data.ProductInfo.ID
        _obj.isCancel = this.isFavorite === 1
        this.isAble = false
        this.AddProductToFavorite(_obj)
      }
    },
    // 分享
    share() {
      this.shareData.show = true
    },
    // 升级
    goUpgrade() {
      console.log('升级')
      if (this.data.ShareRewardInfo.UpgradeLink) {
        window.location = this.data.ShareRewardInfo.UpgradeLink
      }
    },
    // 调用收藏/取消收藏接口
    AddProductToFavorite(obj) {
      AddProductToFavorite(obj).then(res => {
        if (res) {
          this.$toast.success(res.Msg)
          this.isFavorite = this.isFavorite === 1 ? 0 : 1
          this.isAble = true
        }
      })
    }
  }
}
</script>

<style lang="scss" scoped>
// 商品详情头部简介
.product-intro{
  background: $colorF;
  padding: 32px;
  font-size: 24px;
  h1{
    align-items: flex-end;
    line-height: 1;
    position: relative;
    .share{
      margin-left: 13px;
      padding: 10px 14px;
      border-radius: 22px 22px 22px 0;
    }
    .like{
      position: absolute;
      right: 0;
      top: 10px;
    }
  }
  .oldprice{
    text-decoration:line-through;
  }
  h2{
    line-height: 1.5;
    font-weight: 600;
    padding-right: 135px;
    position: relative;
  }
  .share-btn{
    position: absolute;
    right: -32px;
    top: 0;
    font-weight:normal;
    font-size: 24px;
    padding: 10px 16px;
    &:before{
      content:'';
      position: absolute;
      width: 100%;
      height: 100%;
      top: 0;
      left: 0;
      border-radius: 27px 0 0 27px;
      background: currentColor;
      opacity: 0.05;
    }
  }
  .upgrade{
    position: relative;
    p {
      position: absolute;
      left: 22px;
      top: calc(50% - 21px);
    }
  }
}
.van-dialog{
  border-radius: 8px;
}

// 弹窗部分样式
.dialog-box{
  position: fixed;
  height: 100vh;
  width: 100vw;
  top: 0;
  left: 0;
  z-index: 2016;
  .dialog-shadow{
    position: absolute;
    height: 100%;
    width: 100%;
    top:0;
    left: 0;
    background: rgba(0,0,0,0.7);
  }
  .dialog-content{
    position: relative;
    width: 640px;
    margin: 200px auto;
    border-radius: 8px;
    overflow: hidden;
  }
}
</style>
